/*
 * This file is Copyright 2002-2006 Loyola University Chicago,
 * Department of Computer Science and the Emerging Technologies Laboratory.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License via
 *    http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.citep.web.admin.accounts.client;

import java.util.Date;
import java.util.ArrayList;
import com.google.gwt.user.client.rpc.RemoteService;

import com.citep.web.gwt.dto.*;

public interface AccountService extends RemoteService  {
	
	//creates a new account
	public AccountDTO createAccount(String name, String description, String type, int accountCategoryID, String amount, Date startPeriod, Date endPeriod, boolean enabled, AccountDTO parent) throws CitepException,GWTValidationException;
	
	//gets an existing account
	public AccountDTO getAccount(int accountId) throws CitepException;
	
	//gets a list of accounts, sorted alphabetically, in the range (offset, offset+limit)
	public ArrayList getAccounts(int offset, int limit) throws CitepException;
	
	//public ArrayList getTopLevelAccounts() throws CitepException;
	
	//returns an AccountTreeNode structure referencing all of the account's parents all the way to the root account
	//'account' would be the leaf node at the bottom
	public AccountTreeNode getAccountParentHierarchy(AccountDTO account) throws CitepException;
	
	//returns an AccountTreeNode structure referencing all of the accounts children all the way to the bottom
	//'account' is the root node
	public AccountTreeNode getAccountChildrenTree(AccountDTO account) throws CitepException;

	//returns the whole tree of accounts, starting at the first top-level account found
	public AccountTreeNode getAccountTree() throws CitepException;
	
	public Boolean isAccountTreeSynched() throws CitepException;
	
	//saves changes to an existing account
	//we need the parent as well, in case it changed
	public void saveAccount(AccountDTO account, AccountDTO parent) throws CitepException,GWTValidationException;
	
	public AccountCategoryDTO createAccountCategory(String name, String description) throws CitepException,GWTValidationException;
	public ArrayList getAccountCategories() throws CitepException;
	
	//returns the types of account entries ('CREDIT','DEBIT)
	public ArrayList getEntryTypes();
	
	public void createTransaction(AccountDTO source, AccountDTO dest, String entryType, String memo, Date transactionDate, String amount) throws CitepException,GWTValidationException;
	
	/*
	 * Returns a set of com.citep.web.gwt.dto.EntryInfo objects, containing
	 * information about each one of the entries in [offset, offset+limit)
	 */
	public ArrayList getAccountEntries(AccountDTO account, int offset, int limit);
	
	//get the account's balance up to and including this entry
	public String getAccountBalance(AccountDTO account, EntryDTO entry);

	public Date getLatestTransactionTime();
	public Date getLatestTransactionTime(AccountDTO account);
	
	//creates a new user
	public UserDTO createUser(String firstName, String lastName, String email, String password, int roleId) throws CitepException;
	public ArrayList getRoles() throws CitepException;
	public ArrayList getUsers(int offset, int limit) throws CitepException;
	public UserDTO getUser(int userId) throws CitepException;
	public UserDTO login(String email, String password) throws CitepException;

	public void saveUser(UserDTO user) throws CitepException,GWTValidationException;
	
	public StatementDTO getImportedTransactions(int statementNumber) throws CitepException;
	public int getPendingStatementCount() throws CitepException;
	public void setImportedTransactionAccount(int statementNumber, int idx, AccountDTO account);
	public void commitStatementImport(int statementNumber, AccountDTO account);
}
